import torch
import numpy as np
from PIL import Image
from matplotlib import pyplot as plt
from numpy import array
from sklearn.preprocessing import LabelBinarizer
from sklearn.metrics import log_loss
from MainCode.TOOL import ToolClass as tool



font_size = 12
# --------------------读sgy为矩阵------------------------#
# 初始化一个列表存数据，最后再转为矩阵
# data_list = []
# sgy文件路径

def normalization(data):
    _range = np.max(abs(data))
    return data / _range

import os
import segyio
import numpy as np
#
with segyio.open('Kerry3D.segy',ignore_geometry=True) as segyfile:
    segyfile.mmap()
    num_map = segyfile.bin[segyio.BinField.Traces]
    print(segyfile.bin)
    datasets = []
    data_list = []
    print(segyfile.xlines)
    print(segyfile.trace)
    index = 0
    for i in (segyfile.trace):
        # print(i)
        datasets.append(array(i))
        index += 1
    # for i in datasets:
    #     print(i)
    print(index)
# 转为矩阵
index_list = []
data_numpy = np.array(datasets,dtype=np.float64)

data_numpy = np.transpose(data_numpy)
data_numpy = normalization(data_numpy)

print(data_numpy.shape)
# plt.xlabel('Trace number', fontsize=font_size)
# plt.ylabel('Samples', fontsize=font_size)
# im2 = plt.imshow(data_numpy[:,1913:2188], aspect='auto', cmap='seismic', vmin=-1.0, vmax=1.0)
# cb2 = plt.colorbar(im2)
# tick_locator = ticker.MaxNLocator(nbins=5)
# cb2.locator = tick_locator
# cb2.set_ticks([-1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1])
# cb2.update_ticks()
# plt.savefig('denoisedRealData.pdf', format='pdf')
# plt.show()

np.save('realdata', arr=data_numpy[:,1913:2188], allow_pickle=True,fix_imports=True)